<template>
    <el-drawer :title="title" :before-close="handleClose" :visible.sync="showDialog" direction="rtl" append-to-body
        custom-class="drawer-industry-new-modify" ref="drawer" :wrapperClosable="false">
        <div class="drawer-body">
            <el-form ref="form" :model="formData" label-position="right" label-width="150px">
                <el-form-item prop="industryId" label="行业ID" :rules="[{ required: true, message: '行业ID不能为空' }]">
                    <el-input v-model="formData.industryId" autocomplete="off" placeholder="请输入行业ID"
                        :disabled="true"></el-input>
                </el-form-item>
                <el-form-item prop="industryName" label="行业名称" :rules="[{ required: true, message: '行业名称不能为空' }]">
                    <el-input v-model="formData.industryName" autocomplete="off" placeholder="请输入行业名称"
                        :disabled="true"></el-input>
                </el-form-item>
                <el-form-item prop="pre_cmd_para_session_id" label="会话ID"
                    :rules="[{ required: true, message: '会话ID不能为空' }]">
                    <el-input v-model="formData.pre_cmd_para_session_id" autocomplete="off" placeholder="请输入会话ID"
                        :disabled="true"></el-input>
                </el-form-item>
                <el-form-item prop="mid_table_remark_001" label="查询条件" :rules="[{ required: true, message: '查询条件' }]">

                    <el-input type="textarea" v-model="formData.mid_table_remark_001" autocomplete="off"
                        placeholder="请输入查询条件" :autosize="{ minRows: 5, maxRows: 8 }" :disabled="true"
                        resize="none"></el-input>
                </el-form-item>
                <el-form-item prop="mid_table_remark_002" label="查询结果" :rules="[{ required: true, message: '查询结果' }]">
                    <el-input type="textarea" v-model="formData.mid_table_remark_002" autocomplete="off"
                        placeholder="请输入查询结果" :autosize="{ minRows: 5, maxRows: 8 }" resize="none"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button @click="handleClose">取消</el-button>
                    <el-button type="primary" :loading="loading" @click="handleSubmit">{{ loading ? '提交中 ...' : '确定修改'
                    }}</el-button>
                </el-form-item>
            </el-form>


        </div>
    </el-drawer>
</template>
<script>
import { Base64 } from "js-base64";
import { middleList } from "@/api/middle";
import { chatMainApi } from "@/api/chatApi"
export default {
    name: "CompModifyChat",
    data() {
        return {
            showDialog: false,
            title: "",
            formData: {
                industryId: "",
                industryName: "",
                pre_cmd_para_session_id: "",
                // pre_cmd_para_classify_tag: "",
                mid_table_remark_001: "",
                mid_table_remark_002: "",
            },
            loading: false,
            rowInfo: null,
        }
    },
    props: {

    },
    methods: {
        onEditOrAdd(row) {
            if (!row) {
                return;
            }
            this.rowInfo = row;
            console.log(row, ">.>>>>jkjk>>>>")
            let mid_table_remark_001 = row.mid_table_remark_001;
            let mid_table_remark_002 = row.mid_table_remark_002;
            try {
                mid_table_remark_001 = Base64.decode(mid_table_remark_001)
                mid_table_remark_002 = Base64.decode(mid_table_remark_002)
                mid_table_remark_002 = mid_table_remark_002.replace(/<br\s*\/?>/g, "\n")
            } catch (error) {

            }
            this.formData = {
                industryId: row.industryId,
                industryName: row.industryName,
                pre_cmd_para_session_id: row.mid_table_remark_013,
                // pre_cmd_para_classify_tag: "",
                mid_table_remark_001: mid_table_remark_001,
                mid_table_remark_002: mid_table_remark_002,
            }

            this.title = "修改"

            this.showDialog = true;
        },
        handleClose() {
            this.showDialog = false;
            if (this.loading) {
                this.$message.error("数据提交中,暂不能关闭窗口")
            }
        },
        handleSubmit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    // if (this.formData.pre_cmd_para_classify_tag.length < 4) {
                    //     this.$message.error("标签最少四个字")
                    //     return;
                    // }

                    this.onSubmit();
                }
            })
        },
        async onSubmit() {
            if (this.loading) {
                return;
            }
            this.loading = true;
            let postData = {
                invoke_method: "public_insert_or_update_middle_table",
                pre_db_para_middle_table_name:
                    "public_middle_table_lite_mod_ai_chatgpt",
                type_middle_app: 30001,
                type_inner_app: 1001,
                is_online: 0,
                mid_table_remark_001: Base64.encode(this.formData.mid_table_remark_001.replace(/\n/g, "<br>")),
                mid_table_remark_002: Base64.encode(this.formData.mid_table_remark_002.replace(/\n/g, "<br>")),
                pre_db_para_id_public_middle_table: this.rowInfo.id_public_middle_table,
                // mid_table_remark_021: this.formData.mid_table_remark_021,
            };

            middleList(this.Qs.stringify(postData)).then(
                (res) => {
                    this.loading = false
                    this.$notify({
                        title: "Success",
                        message: "保存成功",
                        type: "success",
                        duration: 2000,
                    });
                    this.$emit("refresh");
                    this.showDialog = false;
                },
                (error) => {
                    this.loading = false
                }
            );




        }
    }
}
</script>
<style lang="scss" scoped>
.drawer-industry-new-modify {
    width: 700px;
    padding-right: 10rpx;
    box-sizing: border-box;

    .drawer-body {
        position: relative;
        width: 100%;
        padding-left: 30px;
        padding-right: 30px;
        box-sizing: border-box;
    }
}
</style>
